package com.singerw.utils;

import com.alibaba.fastjson.JSON;
import com.singerw.pojo.Result;
import com.singerw.pojo.ResultEnum;

/**
 * @version V1.0
 * @Package com.singerw.utils
 * @auhter 张欣
 * @date 2021/1/2-7:01 PM
 */
public class ResultUtils {
    public static <T> Result<T> defineSuccess(Integer code, T data) {
        Result result = new Result<>();
        return result.setCode(code).setData(data);
    }

    public static String success(Object data) {
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS).setData(data);
        return JSON.toJSONString(result);
    }
    public static String fail(String msg) {
        Result result = new Result();
        result.setCode(ResultEnum.FAIL).setMsg(msg);
        return JSON.toJSONString(result);
    }

    public static Result noPermission(String msg) {
        Result result = new Result();
        result.setCode(ResultEnum.NO_PERMISSION).setMsg(msg);
        return result;
    }

    public static <T> Result<T> defineFail(int code, String msg){
        Result result = new Result();
        result.setCode(code).setMsg(msg);
        return result;
    }

    public static <T> Result<T> define(int code, String msg, T data){
        Result result = new Result();
        result.setCode(code).setMsg(msg).setData(data);
        return result;
    }
}
